import React from 'react';
import './square.css';
import { findDOMNode } from 'react-dom';
import ReactLife from "./ReactLife";
//点击事件、state状态管理
class Square extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        value: true,
      };
    }
  
    componentDidMount(){
      const dom = findDOMNode(this.node); // 通过findDOMNode获取实例对应的真实DOM
      console.log("componentDidMount=Square=我来了",dom,this);
      // console.log("componentDidMount=Square=我来了");
    }
    componentWillUnmount(){
      const dom = findDOMNode(this.node); // 通过findDOMNode获取实例对应的真实DOM
      console.log("componentWillUnmount=Square=我来了",dom,this);
    }
    render() {
      return (
        <div className="square">
          <div>电灯开关：</div>
          <button
            onClick={
              () => {
                this.node.deleteRow("222",333)
              this.setState({value: !this.state.value }) 
            }}
          >
            {this.state.value ? "ON" : "OFF"}
          </button>
          <ReactLife data={{num:1}} ref={ node=>{ this.node = node} }/>
        </div>
      );
    }
  }

  export default Square;